package cn.strive.eams.virtual.service.impl;

import cn.strive.eams.virtual.mapper.VirtualMapper;
import cn.strive.eams.virtual.pojo.dto.VirtualQuery;
import cn.strive.eams.virtual.pojo.dto.VirtualSaveParam;
import cn.strive.eams.virtual.pojo.entity.Virtual;
import cn.strive.eams.virtual.pojo.vo.VirtualVO;
import cn.strive.eams.virtual.service.VirtualService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class VirtualServiceImpl implements VirtualService {
    @Autowired
    VirtualMapper virtualMapper;

    @Override
    public List<VirtualVO> selectVirtual(VirtualQuery virtualQuery) {
        log.debug("查询虚拟资产业务:virtualQuery={}",virtualQuery);
        List<VirtualVO>list = virtualMapper.selectVirtual(virtualQuery);
        return list;
    }

    @Override
    public void saveVirtual(VirtualSaveParam virtualSaveParam) {
        log.debug("保存虚拟资产业务:virtualSaveParam={}",virtualSaveParam);
        Virtual virtual = new Virtual();
        BeanUtils.copyProperties(virtualSaveParam,virtual);
        if (virtual.getId() == null){
            virtual.setCreateTime(new Date());
            virtualMapper.insert(virtual);
        }else {
            virtual.setUpdateTime(new Date());
            virtualMapper.update(virtual);
        }
    }

    @Override
    public void deleteVirtual(Long id) {
        log.debug("删除虚拟资产业务:id={}",id);
        virtualMapper.deleteVirtual(id);
    }

    @Override
    public void deleteBatch(List<Long> ids) {
        log.debug("批量删除虚拟资产业务:ids={}", ids);
        for (Long id : ids){
            virtualMapper.deleteVirtual(id);
        }
    }
}
